define(['jquery', 'jquery-weui', 'weui', 'common'], function ($, JqueryWuei, Weui) {
    var Controller = {
        index: function () {
            //上传按钮事件
            Controller.api.upload();

            $(".datetime-picker").calendar();
            $('#formSubmitBtn').click(function () {
                // event.preventDefault();
                var reception_id = $(".weui-select").val();
                if (reception_id == 0) {
                    alert('请选择接待单位');
                    return false;
                }
                if($("#healthy_pic_input").val() == ""){
                    alert('请上传健康码');
                    return false;
                }
                if($("#trip_pic_input").val() == ""){
                    alert('请上传14天行程码');
                    return false;
                }
                Weui.form.validate('#form1', function (error) {
                    console.log(error);
                    if (!error) {
                        setbutton(0);
                        $.ajax({
                            //几个参数需要注意一下
                            type: "POST",//方法类型
                            dataType: "json",//预期服务器返回的数据类型
                            url: "/index.php/index/outsideschool",//url
                            data: $('#form1').serialize(),
                            success: function (ret) {
                                if (ret.code == 1) {
                                    $.alert({
                                        title: ret.msg,
                                        text: ret.data.nickname + '&nbsp;您好,申请成功,<br/>待负责人审核通过后可扫码进入。',
                                        onOK: function () {
                                            // WeixinJSBridge.invoke('closeWindow', {}, function (res) { });
                                            window.location.href = "/index/outsideschool/index";
                                        }
                                    });
                                } else if (ret.code == 0) {
                                    $.alert({
                                        title: '提示',
                                        text: ret.msg,
                                        onOK: function () {
                                            window.location.href = "/index/outsideschool/index";
                                        }
                                    });
                                }
                                // if(ret.code == 1)
                                //
                            },
                            error: function (error) {
                                console.log(error);
                                alert(JSON.stringify(error))
                                $.alert({
                                    title: '提示',
                                    text: '网络异常,请再次提交！',
                                    onOK: function () {
                                        setbutton(1);
                                    }
                                });
                                // alert("异常！");
                            }
                        });
                    }

                }, {
                    regexp: {
                        IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/,

                    }
                });
                return false;
            });
        },
        index2: function () {
            //上传按钮事件
            Controller.api.upload();

            $(".datetime-picker").calendar();
            $('#formSubmitBtn').click(function () {
                // event.preventDefault();
                var reception_id = $(".weui-select").val();
                if (reception_id == 0) {
                    alert('请选择接待单位');
                    return false;
                }
                if($("#healthy_pic_input").val() == ""){
                    alert('请上传健康码');
                    return false;
                }
                Weui.form.validate('#form1', function (error) {
                    console.log(error);
                    if (!error) {
                        setbutton(0);
                        $.ajax({
                            //几个参数需要注意一下
                            type: "POST",//方法类型
                            dataType: "json",//预期服务器返回的数据类型
                            url: "/index.php/index/outsideschool/index2",//url
                            data: $('#form1').serialize(),
                            success: function (ret) {
                                if (ret.code == 1) {
                                    $.alert({
                                        title: ret.msg,
                                        text: ret.data.nickname + '&nbsp;您好,申请成功,<br/>待负责人审核通过后可扫码进入。',
                                        onOK: function () {
                                            // WeixinJSBridge.invoke('closeWindow', {}, function (res) { });
                                            window.location.href = "/index/outsideschool/index";
                                        }
                                    });
                                } else if (ret.code == 0) {
                                    $.alert({
                                        title: '提示',
                                        text: ret.msg,
                                        onOK: function () {
                                            window.location.href = "/index/outsideschool/index";
                                        }
                                    });
                                }
                                // if(ret.code == 1)
                                //
                            },
                            error: function (error) {
                                console.log(error);
                                alert(JSON.stringify(error))
                                $.alert({
                                    title: '提示',
                                    text: '网络异常,请再次提交！',
                                    onOK: function () {
                                        setbutton(1);
                                    }
                                });
                                // alert("异常！");
                            }
                        });
                    }

                }, {
                    regexp: {
                        IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/,

                    }
                });
                return false;
            });
        },
        info: function () {
            // $("#admission_time").calendar();
            // $(".datetime-picker").calendar();
            var $gallery = $("#gallery"), $galleryImg = $("#galleryImg"),
                $uploaderInput = $("#uploaderInput"),
                $uploaderFiles = $("#uploaderFiles");
            $uploaderFiles.on("click", "li", function () {
                $galleryImg.attr("style", this.getAttribute("style"));
                $gallery.fadeIn(100);
            });
            $gallery.on("click", function () {
                $gallery.fadeOut(100);
            });
            $("#ImgID").click(function () {
                var img = $(this).attr('img');
                var src= "<img src='"+img+"' style='width: 100%;height:100%'>";
                $.alert({
                    text: src,
                });
                $(".weui-dialog__title").html("");
            });
            $("#ImgID1").click(function () {
                var img = $(this).attr('img');
                var src= "<img src='"+img+"' style='width: 100%;height:100%'>";
                $.alert({
                    text: src,
                });
                $(".weui-dialog__title").html("");
            });
            $("#ImgID2").click(function () {
                var img = $(this).attr('img');
                var src= "<img src='"+img+"' style='width: 100%;height:100%'>";
                $.alert({
                    text: src,
                });
                $(".weui-dialog__title").html("");
            });
            $('.SubmitBtn').click(function () {
                // event.preventDefault();
                // Weui.form.validate('#form1', function (error) {
                //     console.log(error);
                //     if (!error) {
                // setbutton(0);
                var check = $(this).data('check');
                var data = $.param({"row[check]": check}) + "&" + $("#form2").serialize() + "";
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/index.php/index/outsideschool/ajax",//url
                    data: data,
                    success: function (ret) {
                        if (ret.code == 1) {
                            $.alert({
                                title: ret.msg,
                                // text: '您好,申请成功,<br/>待负责人审核通过后可扫码进入。',
                                onOK: function () {
                                    window.history.go(-1);
                                    // window.location.href = "/index/outsideschool/view";
                                }
                            });
                        } else if (ret.code == 0) {
                            $.alert({
                                title: '提示',
                                text: ret.msg,
                                onOK: function () {
                                    window.history.go(-1);
                                    // window.location.href = "/index/outsideschool/view";
                                }
                            });
                        }
                        // if(ret.code == 1)
                        //
                    },
                    error: function (error) {
                        console.log(error);
                        alert(JSON.stringify(error))
                        $.alert({
                            title: '提示',
                            text: '网络异常,请再次提交！',
                            onOK: function () {
                                window.history.go(-1);
                                // window.location.href = "/index/outsideschool/view";
                            }
                        });
                        // alert("异常！");
                    }
                });
                //     }

                // }, {
                //     regexp: {
                //         IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/,

                //     }
                // });
                // return false;
            });

        },
        view: function (from = 'view') {

            var pages = 1;
            var sizes = 13;
            var is_check = 0;
            var keyword = '';
            var loading = false;  //状态标记
            if (from == 'view'){
                var data_url = "/index/outsideschool/view";
            } else{
                var data_url = "/index/outsideschool/log";
            }
            // =======加载数据loadlist();
            function loadlist() {
                var html = "";
                $.ajax({
                    type: "POST",
                    url: data_url,
                    data: {page: pages, size: sizes, keyword: keyword, is_check: is_check},
                    dataType: "json",
                    error: function (request) {
                        $(".weui-loadmore").hide();
                        html += "<div class=\"weui-cells__title\" style='padding-top: 30px;text-align: center'>已无更多数据</div>";
                        $("#Tolist").append(html);
                    },
                    success: function (data) {
                        if (data.data.data.length > 0) {
                            var list = data.data.data;
                            for (var i = 0; i < list.length; i++) {
                                var p = list[i];
                                html += ' <div class="list-group-item "> ';
                                html += ' <input type="checkbox" name="outsides" class="outsides_ids" value="'+p.id+'">';
                                html += ' <div><h4 class="list-group-item-heading company_name">' + p.key + '. 姓名：' + p.nickname + '</h4> ';
                                html += ' <p class="list-group-item-text"><a href="/index/outsideschool/info/id/' + p.id + '/from/' + from + '" > ';
                                html += ' <small>身份证号：' + p.card_id + ' </small><br/> ';
                                html += ' <small>手机号码： ' + p.tel + '    </small><br/> ';
                                html += ' <small>申&nbsp;&nbsp;请&nbsp;&nbsp;人： ' + p.applier_name + '</small><br/> ';
                                html += ' <small>入校时间：' + p.admission_time + '</small></br> ';
                                html += ' <small>申请时间：' + p.create_time_text + '</small></br> ';
                                html += ' <small>审核状态：' + p.is_check_text + '</small></br>';
                                if (p.is_check != 0) {
                                    html += ' <small>审核人员：' + p.check_cn + '</small></br>';
                                    html += ' <small>审核时间：' + p.check_time_text + '</small></br>';
                                    if (p.is_check == 1) {
                                        if (p.is_use == 1) {
                                            html += ' <small>进校状态：' + p.is_use_text + '</small></br>';
                                            html += ' <small>进校时间：' + p.use_time_text + '</small></br> ';
                                            html += ' <small>进校校门：' + p.gate_name + '</small> ';
                                        } else {
                                            html += ' <small>进校状态：' + p.is_use_text + '</small>';
                                        }
                                    }
                                }

                                html += ' </a></p></div></div> ';

                            }
                            $("#Tolist").append(html);

                        }
                        if ((data.data.current_page == 1) && !data.data.data.length) {
                            html = "<div class=\"weui-cells__title\" style='padding-top: 15px;text-align: center'>暂无数据</div>";
                            $("#Tolist").append(html);
                            loading = true;
                        } else {
                            if (data.data.current_page >= data.data.last_page) {
                                html = "<div class=\"weui-cells__title\" style='text-align: center'>已无更多数据</div>";
                                $("#Tolist").append(html);
                                loading = true;
                            }
                        }

                        $(".weui-loadmore").hide();

                        setTimeout(function () {
                            $("#listwrap").pullToRefreshDone(); // 重置下拉刷新
                        }, 700);   //模拟延迟
                    }
                });
            }

            loadlist();

            $("#listwrap").pullToRefresh().on("pull-to-refresh", function () {
                pages = 1;
                $("#Tolist").html("");
                loadlist();
                if (loading) loading = false;

            });
            //============================滚动加载
            $("#listwrap").infinite().on("infinite", function () {
                if (loading) return;
                loading = true;
                pages++; //页数
                $('.weui-loadmore').show();
                loadlist();
                loading = false;
            });

            //搜索
            $('.search_btn').click(function () {
                //搜索条件
                // is_check = $(this).data('value');
                is_check = $('.dropdown-main li.dropdown-chose').data('value');
                keyword = $('.input-search').val();
                pages = 1;
                $("#Tolist").html("");
                loadlist();
                if (loading) loading = false;
            });

            //一键通过
            $('.btn-pass').click(function () {
                var chk_value =[];    
                $('input[name="outsides"]:checked').each(function(){    
                   chk_value.push($(this).val());    
                }); 
                // $.alert({
                //     title: '提示',
                //     text: '默认为全部审核,如若选择单个审核，可选中单条后再审核',
                //     onOK: function () {
                        
                //     }
                // });
                console.log(chk_value);
                // return false;
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/index.php/index/outsideschool/allpass/ids/"+chk_value,//url
                    data: {},
                    success: function (ret) {
                        if (ret.code == 1) {
                            $.alert({
                                title: ret.msg,
                                onOK: function () {
                                    window.location.href="";
                                }
                            });
                        } else if (ret.code == 0) {
                            $.alert({
                                title: '提示',
                                text: ret.msg,
                                onOK: function () {
                                    window.location.href="";
                                }
                            });
                        }
                    },
                    error: function (error) {
                        console.log(error);
                        alert(JSON.stringify(error))
                        $.alert({
                            title: '提示',
                            text: '网络异常,请再次提交！',
                            onOK: function () {
                                window.location.href="";
                            }
                        });
                    }
                });
            });

        },
        log: function () {
            Controller.view('log');
        },
        api: {
            upload: function () {
                var allowTypes = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'];
                // 1024KB，也就是 1MB
                var maxSize = 1024 * 1024;
                // 图片最大宽度
                var maxWidth = 800;
                var maxHeight = 800;
                var pic_config = {
                    width: 700,
                    height: 700,
                    quality: 1
                };
                // 最大上传图片数量
                var maxCount = 1;

                var tmpl = '<li class="weui-uploader__file weui-uploader__file_status" id="#ImgID#" style="background-image:url(#url#)"> <div class="weui-uploader__file-content"></div></li>',
                    $gallery = $("#gallery"),
                    $galleryImg = $("#galleryImg"),
                    $uploaderInput = $("#uploaderInput"),
                    $uploaderFiles = $("#uploaderFiles"),
                    $uploaderInput1 = $("#uploaderInput1"),
                    $uploaderFiles1 = $("#uploaderFiles1"),
                    $uploaderInput2 = $("#uploaderInput2"),
                    $uploaderFiles2 = $("#uploaderFiles2"),

                    $galleryDelete = $(".weui-gallery__opr"),
                    $previewer = $(".previewer");

                var u = navigator.userAgent;
                if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {

                    // $("#uploaderInput").attr('capture', 'camera');
                }
                $uploaderInput.on("change", function (event) {

                    var src, url = window.URL || window.webkitURL || window.mozURL, files = event.target.files;
                    if (files.length === 0) {
                        return;
                    }

                    var fd = new FormData();
                    for (var i = 0, len = files.length; i < len; i++) {
                        console.log(i)
                        var file = files[i];
                        var fileType = file.type;
                        var reader = new FileReader();
                        //     // 如果类型不在允许的类型范围内
                        if (allowTypes.indexOf(file.type) === -1) {
                            $.toast('该类型不允许上传' + fileType, "forbidden");
                            continue;
                        }
                        // if (file.size > maxSize) {
                        //     $.toast("图片太大，不允许上传", "forbidden");
                        //     continue;
                        // }
                        if ($('#uploaderFiles > .weui-uploader__file').length >= maxCount) {
                            $.toast('最多只能上传' + maxCount + '张图片', "forbidden");
                            return;
                        }

                        // if (url) {
                        //     src = url.createObjectURL(file);
                        // } else {
                        //     src = event.target.result;
                        // }
                        //  $uploaderFiles.append($(tmpl.replace('#url#', src)));
                        // // console.log(src);

                        // // var form=document.getElementById("form1");

                        src = url.createObjectURL(file);

                        // reader.onload = function (e) {


                        var img = new Image();
                        (function (i) {
                            Controller.api.compressImage(src, pic_config, function (result) {
                                console.log(result);
                                console.log(i);

                                fd.append("file", result);
                                $.ajax({
                                    url: "/api/common/upload",
                                    type: "POST",
                                    data: fd,
                                    dataType: 'json',
                                    processData: false,  // 告诉jQuery不要去处理发送的数据
                                    contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
                                    async: false,
                                    success: function (res) {
                                        console.log(res);

                                        // $.alert(JSON.stringify(res));
                                        // if($("#pic_ids").val()=='')
                                        //     $("#pic_ids").val(res.id);
                                        // else
                                        //     $("#pic_ids").val($("#pic_ids").val()+","+res.id);
                                        $('#healthy_pic_input').val(res.data.url);
                                        var num = $('#uploaderFiles > .weui-uploader__file').length;
                                        console.log(num);
                                        $('.weui-uploader__info').text(num + '/' + maxCount);
                                        var $preview = $('<li class="weui-uploader__file weui-uploader__file_status" id="ImgID" style="position:relative;background-image:url(' + res.data.url + ')"><div class="close-icon"></div><div class="weui-uploader__file-content">0%</div></li>');
                                        $uploaderFiles.append($preview);
                                        // $uploaderFiles.append($(tmpl.replace('#url#', img.src).replace('#ImgID#',res.id)));
                                        // $uploaderFiles.append($(tmpl.replace('#url#', img.src)));
                                        // $preview.attr('id',res.id);
                                        $preview.removeClass('weui-uploader__file_status').find('.weui-uploader__file-content').remove();

                                    }
                                });
                            })
                        })(i)
                    }
                });
                
                $uploaderInput1.on("change", function (event) {

                    var src, url = window.URL || window.webkitURL || window.mozURL, files = event.target.files;
                    if (files.length === 0) {
                        return;
                    }

                    var fd = new FormData();
                    for (var i = 0, len = files.length; i < len; i++) {
                        console.log(i)
                        var file = files[i];
                        var fileType = file.type;
                        var reader = new FileReader();
                        //     // 如果类型不在允许的类型范围内
                        if (allowTypes.indexOf(file.type) === -1) {
                            $.toast('该类型不允许上传' + fileType, "forbidden");
                            continue;
                        }

                        if ($('#uploaderFiles1 > .weui-uploader__file').length >= maxCount) {
                            $.toast('最多只能上传' + maxCount + '张图片', "forbidden");
                            return;
                        }

                        src = url.createObjectURL(file);

                        var img = new Image();
                        (function (i) {
                            Controller.api.compressImage(src, pic_config, function (result) {
                                console.log(result);
                                console.log(i);

                                fd.append("file", result);
                                $.ajax({
                                    url: "/api/common/upload",
                                    type: "POST",
                                    data: fd,
                                    dataType: 'json',
                                    processData: false,  // 告诉jQuery不要去处理发送的数据
                                    contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
                                    async: false,
                                    success: function (res) {
                                        console.log(res);

                                        $('#trip_pic_input').val(res.data.url);
                                        var num = $('#uploaderFiles1 > .weui-uploader__file').length;
                                        console.log(num);
                                        $('.weui-uploader__info').text(num + '/' + maxCount);
                                        var $preview = $('<li class="weui-uploader__file weui-uploader__file_status" id="ImgID" style="position:relative;background-image:url(' + res.data.url + ')"><div class="close-icon"></div><div class="weui-uploader__file-content">0%</div></li>');
                                        $uploaderFiles1.append($preview);
                                        // $uploaderFiles.append($(tmpl.replace('#url#', img.src).replace('#ImgID#',res.id)));
                                        // $uploaderFiles.append($(tmpl.replace('#url#', img.src)));
                                        // $preview.attr('id',res.id);
                                        $preview.removeClass('weui-uploader__file_status').find('.weui-uploader__file-content').remove();

                                    }
                                });
                            })
                        })(i)
                    }
                });

                $uploaderInput2.on("change", function (event) {

                    var src, url = window.URL || window.webkitURL || window.mozURL, files = event.target.files;
                    if (files.length === 0) {
                        return;
                    }

                    var fd = new FormData();
                    for (var i = 0, len = files.length; i < len; i++) {
                        console.log(i)
                        var file = files[i];
                        var fileType = file.type;
                        var reader = new FileReader();
                        //     // 如果类型不在允许的类型范围内
                        if (allowTypes.indexOf(file.type) === -1) {
                            $.toast('该类型不允许上传' + fileType, "forbidden");
                            continue;
                        }

                        if ($('#uploaderFiles2 > .weui-uploader__file').length >= maxCount) {
                            $.toast('最多只能上传' + maxCount + '张图片', "forbidden");
                            return;
                        }

                        src = url.createObjectURL(file);

                        var img = new Image();
                        (function (i) {
                            Controller.api.compressImage(src, pic_config, function (result) {
                                console.log(result);
                                console.log(i);

                                fd.append("file", result);
                                $.ajax({
                                    url: "/api/common/upload",
                                    type: "POST",
                                    data: fd,
                                    dataType: 'json',
                                    processData: false,  // 告诉jQuery不要去处理发送的数据
                                    contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
                                    async: false,
                                    success: function (res) {
                                        console.log(res);

                                        $('#nuclein_pic_input').val(res.data.url);
                                        var num = $('#uploaderFiles2 > .weui-uploader__file').length;
                                        console.log(num);
                                        $('.weui-uploader__info').text(num + '/' + maxCount);
                                        var $preview = $('<li class="weui-uploader__file weui-uploader__file_status" id="ImgID" style="position:relative;background-image:url(' + res.data.url + ')"><div class="close-icon"></div><div class="weui-uploader__file-content">0%</div></li>');
                                        $uploaderFiles2.append($preview);
                                        // $uploaderFiles.append($(tmpl.replace('#url#', img.src).replace('#ImgID#',res.id)));
                                        // $uploaderFiles.append($(tmpl.replace('#url#', img.src)));
                                        // $preview.attr('id',res.id);
                                        $preview.removeClass('weui-uploader__file_status').find('.weui-uploader__file-content').remove();

                                    }
                                });
                            })
                        })(i)
                    }
                });

                var index;
                $uploaderFiles.on("click", "li", function () {
                    console.log(12312);
                    index = $(this).index();
                    $galleryImg.attr("style", this.getAttribute("style"));
                    $galleryDelete.show();
                    $gallery.fadeIn(100);
                });
                $uploaderFiles1.on("click", "li", function () {
                    console.log(12312);
                    index = $(this).index();
                    $galleryImg.attr("style", this.getAttribute("style"));
                    $galleryDelete.show();
                    $gallery.fadeIn(100);
                });
                $uploaderFiles2.on("click", "li", function () {
                    console.log(12312);
                    index = $(this).index();
                    $galleryImg.attr("style", this.getAttribute("style"));
                    $galleryDelete.show();
                    $gallery.fadeIn(100);
                });

                $('.image-previewer-box').on("click", "li", function () {
                    index = $(this).index();
                    $galleryImg.attr("style", this.getAttribute("style"));
                    $galleryDelete.hide();
                    $gallery.fadeIn(100);
                });
                $('.image-previewer-box').on("click", ".close-icon", function () {
                    $(this).parent('li').remove();
                });

                $gallery.on("click", function () {
                    $gallery.fadeOut(100);
                });


                $(".weui-gallery__del").click(function () {
                    var picid = $uploaderFiles.find("li").eq(index).attr("id");

                    $uploaderFiles.find("li").eq(index).remove();
                    str = $("#pic_ids").val();
                    newstr = (',' + str + ',').replace(',' + picid + ',', ',').substr(1).replace(/,$/, '');
                    $("#pic_ids").val(newstr);

                    // $.ajax({
                    //         url: "deletePic/ids/"+picid,
                    //         dataType : 'json',
                    //         success: function(res){

                    //     }
                    // });

                })
            },
            convertBase64UrlToBlob: function (urlData) {
                console.log(urlData);
                var arr = urlData.split(',')
                var mime = arr[0].match(/:(.*?);/)[1]
                console.log(mime)
                var bstr = atob(arr[1])
                var n = bstr.length
                var u8arr = new Uint8Array(n)
                while (n--) {
                    u8arr[n] = bstr.charCodeAt(n)
                }
                return new Blob([u8arr], {type: mime})
            },
            convertBase64UrltoFile: function (dataurl) {
                var filename = 'file'
                var arr = dataurl.split(',')
                var mime = arr[0].match(/:(.*?);/)[1]
                var suffix = mime.split('/')[1]
                var bstr = atob(arr[1])
                var n = bstr.length
                var u8arr = new Uint8Array(n)
                while (n--) {
                    u8arr[n] = bstr.charCodeAt(n)
                }
                return new File([u8arr], filename + '.' + suffix, {
                    type: mime
                })
            },
            compressImage: function (path, config, callback) {

                var img = new Image()
                img.src = path
                img.onload = function () {
                    var that = this
                    var width_ratio = config.width / that.width;
                    var height_ratio = config.height / that.height;
                    if (width_ratio >= height_ratio) {
                        var w = Math.min(config.width, that.width);
                        // 高度按比例计算
                        var h = that.height * (w / that.width);
                    }
                    // 源图过宽
                    else if (width_ratio <= height_ratio) {

                        var h = Math.min(config.height, that.height);
                        var w = that.width * (h / that.height);
                    }
                    var quality = 0.7 // 默认图片质量为0.7
                    // 生成canvas
                    var canvas = document.createElement('canvas')
                    var ctx = canvas.getContext('2d')
                    // 创建属性节点
                    var anw = document.createAttribute('width')
                    anw.nodeValue = w
                    var anh = document.createAttribute('height')
                    anh.nodeValue = h
                    canvas.setAttributeNode(anw)
                    canvas.setAttributeNode(anh)
                    ctx.drawImage(that, 0, 0, w, h)
                    if (config.quality && config.quality <= 1 && config.quality > 0) {
                        quality = config.quality
                    }
                    var base64 = canvas.toDataURL('image/*', quality)
                    var blob = Controller.api.convertBase64UrltoFile(base64)
                    // 回调函数返回blob的值（若不需要，可直接返回base64的值）
                    callback(blob)
                }
            },

        }
    };
    return Controller;
});


